#pragma once

using namespace System;
using namespace NUnit::Framework;
using namespace LatoolNet;

namespace LatoolNetTest {

	[TestFixture]
	public ref class DoubleSymmetricBandMatrixTest {
	public:


		[Test]
		void TestFactorizeAndSolve() {
			
			int rownum = 4;
			int colnum = 4;

			Matrix ^a = gcnew Matrix(rownum, colnum, MatrixType::DoubleSymmetricBand, 1, 1);
			a[0, 0] = 5.49;
			a[0, 1] = 2.68;

			a[1, 1] = 5.63;
			a[1, 2] = -2.39;

			a[2, 2] = 2.60;
			a[2, 3] = -2.22;

			a[3, 3] = 5.17;

			//Console::WriteLine(a->ToString());

			Matrix ^ b = gcnew Matrix(rownum, 1);

			b[0, 0] = 22.09;
			b[1, 0] = 9.31;
			b[2, 0] = -5.24;
			b[3, 0] = 11.83;

			//LUFactorization::Factorize(a);
			LinearEquation::Factorize(a);

			//Console::WriteLine(a->ToString());
			//LUFactorization::Solve(a, b);
			LinearEquation::Solve(a, b);

			//Console::WriteLine(b->ToString());
			Assert::AreEqual(5.0, b[0, 0], 1e-10, "Test: Positive-definite Factorize And Solve.");
			Assert::AreEqual(-2.0, b[1, 0], 1e-10, "Test: Positive-definite Factorize And Solve.");
			Assert::AreEqual(-3.0, b[2, 0], 1e-10, "Test: Positive-definite Factorize And Solve.");
			Assert::AreEqual(1.0, b[3, 0], 1e-10, "Test: Positive-definite Factorize And Solve.");

		};

		[Test]
		void TestSolve() {
			
			int rownum = 4;
			int colnum = 4;

			Matrix ^a = gcnew Matrix(rownum, colnum, MatrixType::DoubleSymmetricBand, 1, 1);
			a[0, 0] = 5.49;
			a[0, 1] = 2.68;

			a[1, 1] = 5.63;
			a[1, 2] = -2.39;

			a[2, 2] = 2.60;
			a[2, 3] = -2.22;

			a[3, 3] = 5.17;

			//Console::WriteLine(a->ToString());

			Matrix ^ b = gcnew Matrix(rownum, 1);

			b[0, 0] = 22.09;
			b[1, 0] = 9.31;
			b[2, 0] = -5.24;
			b[3, 0] = 11.83;

			//Console::WriteLine(a->ToString());
			//LUFactorization::Solve(a, b);
			LinearEquation::Solve(a, b);
			//Console::WriteLine(b->ToString());
			Assert::AreEqual(5.0, b[0, 0], 1e-10, "Test: Positive-definite Factorize And Solve.");
			Assert::AreEqual(-2.0, b[1, 0], 1e-10, "Test: Positive-definite Factorize And Solve.");
			Assert::AreEqual(-3.0, b[2, 0], 1e-10, "Test: Positive-definite Factorize And Solve.");
			Assert::AreEqual(1.0, b[3, 0], 1e-10, "Test: Positive-definite Factorize And Solve.");

		};

	};
}
